<?php
//=======================================
//###################################
// Kayako Web Solutions
//
// Source Copyright 2001-2004 Kayako Web Solutions
// Unauthorized reproduction is not allowed
// License Number: $%LICENSE%$
// $Author: vshoor $ ($Date: 2007/06/20 05:48:12 $)
// $RCSfile: functions_settings.php,v $ : $Revision: 1.6 $ 
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//###################################
//=======================================


if (!defined("INSWIFT")) {
	trigger_error("Unable to process $PHP_SELF", E_USER_ERROR);
}

/**
* Builds an option list of languages
*/
function buildLanguageList()
{
	global $dbCore;

	$dbCore->query("SELECT * FROM `". TABLE_PREFIX ."languages` ORDER BY `title` ASC;", 3);
	while ($dbCore->nextRecord(3))
	{
		$options .= '<option value="'. $dbCore->Record3["languagecode"] .'"'. iif($dbCore->Record3["isdefault"]==1, " selected") .'>'. htmlspecialchars($dbCore->Record3["title"]) .'</option>'.SWIFT_CRLF;
	}

	return $options;
}

/**
* Generate Ticket Status
*/
function generateClientTicketStatus()
{
	global $dbCore, $_SWIFT;

	$options = '<option value="0"'. iif($_SWIFT["settings"]["t_cstatusupd"]==0, " selected") .'>'. htmlspecialchars($_SWIFT["language"]["tsnochange"]) .'</option>'.SWIFT_CRLF;

	$dbCore->query("SELECT * FROM `". TABLE_PREFIX ."ticketstatus` ORDER BY `displayorder` ASC;", 3);
	while ($dbCore->nextRecord(3))
	{
		$options .= '<option value="'. $dbCore->Record3["ticketstatusid"] .'"'. iif($_SWIFT["settings"]["t_cstatusupd"]==$dbCore->Record3["ticketstatusid"], " selected") .'>'. htmlspecialchars($dbCore->Record3["title"]) .'</option>'.SWIFT_CRLF;
	}

	return $options;
}

/**
* Generate Ticket Status
*/
function generateAutoCloseTicketStatus()
{
	global $dbCore, $_SWIFT;

	$dbCore->query("SELECT * FROM `". TABLE_PREFIX ."ticketstatus` ORDER BY `displayorder` ASC;", 3);
	while ($dbCore->nextRecord(3))
	{
		$options .= '<option value="'. $dbCore->Record3["ticketstatusid"] .'"'. iif(@in_array($dbCore->Record3["ticketstatusid"], $_SWIFT["settings"]["t_acstatus"]), " selected") .'>'. htmlspecialchars($dbCore->Record3["title"]) .'</option>'.SWIFT_CRLF;
	}

	return $options;
}

/**
* Generate Ticket Status
*/
function generateAutoCloseFinalStatus()
{
	global $dbCore, $_SWIFT;

	$dbCore->query("SELECT * FROM `". TABLE_PREFIX ."ticketstatus` ORDER BY `displayorder` ASC;", 3);
	while ($dbCore->nextRecord(3))
	{
		$options .= '<option value="'. $dbCore->Record3["ticketstatusid"] .'"'. iif($dbCore->Record3["ticketstatusid"] == $_SWIFT["settings"]["t_acstatusch"], " selected") .'>'. htmlspecialchars($dbCore->Record3["title"]) .'</option>'.SWIFT_CRLF;
	}

	return $options;
}

/**
* Generate Departments
*/
function generateAutoCloseDepartments()
{
	global $dbCore, $_SWIFT;

	$dbCore->query("SELECT * FROM `". TABLE_PREFIX ."departments` ORDER BY `displayorder` ASC;", 3);
	while ($dbCore->nextRecord(3))
	{
		if ($dbCore->Record3["departmentmodule"] == MODULE_TICKETS)
		{
		$options .= '<option value="'. $dbCore->Record3["departmentid"] .'"'. iif(@in_array($dbCore->Record3["departmentid"], $_SWIFT["settings"]["t_acdep"]), " selected") .'>'. htmlspecialchars($dbCore->Record3["title"]) .'</option>'.SWIFT_CRLF;
		}
	}

	return $options;
}

/**
* Generate list of staff users
*/
function generateAPIStaffUsers()
{
	global $dbCore, $_SWIFT;

	$dbCore->query("SELECT * FROM `". TABLE_PREFIX ."staff` ORDER BY `fullname` ASC;", 3);
	while ($dbCore->nextRecord(3))
	{
		$options .= '<option value="'. $dbCore->Record3["staffid"] .'"'. iif(in_array($dbCore->Record3["staffid"], $_SWIFT["settings"]["t_apistaffusers"])," selected") .'>'. htmlspecialchars($dbCore->Record3["fullname"]) .' ('. htmlspecialchars($dbCore->Record3["username"]) .')</option>'.SWIFT_CRLF;
	}

	return $options;
}

/**
* Generates a list of template groups
*/
function generateMBTemplateGroupOptions()
{
	global $dbCore, $_SWIFT;

	$dbCore->query("SELECT * FROM `". TABLE_PREFIX ."templategroups` ORDER BY `title` ASC;", 3);
	while ($dbCore->nextRecord(3))
	{
		$options .= '<option value="'. $dbCore->Record3["tgroupid"] .'"'. iif($_SWIFT["settings"]["g_mbtgroup"]==$dbCore->Record3["tgroupid"], " selected") .'>'. htmlspecialchars($dbCore->Record3["title"]).'</option>'.SWIFT_CRLF;
	}

	return $options;
}
?>